package ThreadService;

import service.CommandTypeEnum;
import service.IOService;
import service.RmCommand;
import service.SetCommand;
//备份
public class BackupThread extends Thread {
    private IOService ioService;
    private String key;
    private String value;
    private String type;

    public BackupThread(String key, String value, CommandTypeEnum typeEnum) {
        this.key = key;
        this.value = value;
        this.type = typeEnum.name();
    }

    @Override
    public void run() {
        ioService = new IOService();
        String str = null;
        //因为set和rm都是对文件的修改，所以都需要进行备份处理
        if (type.equals(CommandTypeEnum.Set.name())) str = new SetCommand(key, value).toString();
        else str = new RmCommand(key).toString();
        //io写入文件
        ioService.write(str);
    }
}
